package com.example.g2daylx2

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.widget.SearchView.OnQueryTextListener
import androidx.core.view.GravityCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.g2daylx2.adapter.CarAdapter
import com.example.g2daylx2.bvm.CarViewModel
import com.example.g2daylx2.bvm.QweViewModel
import com.example.g2daylx2.databinding.ActivityCcarBinding
import com.example.lib_base.net.mvvm.BaseActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@Route(path = "/app/CcarActivity")
@AndroidEntryPoint
class CcarActivity : BaseActivity<ActivityCcarBinding,QweViewModel>() {
   lateinit var carAdapter:CarAdapter

    override fun initView() {
        carAdapter = CarAdapter()
        binding.rv.adapter = carAdapter
        binding.rv.layoutManager = LinearLayoutManager(this)
        vm.getQwe("标准车位")

        binding.chou.setOnClickListener {
            binding.br.openDrawer(GravityCompat.END)
        }
        carAdapter.addChildClickViewIds(R.id.park_status)
        binding.rbKx.setOnClickListener {

            vm.getStatus("空闲")

        }
        binding.rbWh.setOnClickListener {
            vm.getStatus("维护中")
        }
        binding.rbZy.setOnClickListener {
            vm.getStatus("已占用")
        }

        binding.sv.setOnQueryTextListener(object : OnQueryTextListener{
            override fun onQueryTextSubmit(query: String?): Boolean {
                vm.getArea(query!!.toInt())
                return true
            }

            override fun onQueryTextChange(newText: String?): Boolean {
                return true
            }
        })
    }

    override fun initData() {
        vm.carSuccess.observe(this){
            carAdapter.data.clear()
            carAdapter.data.addAll(it)
            carAdapter.notifyDataSetChanged()
        }
        vm.statusSuccess.observe(this){
            carAdapter.data.clear()
            carAdapter.data.addAll(it)
            carAdapter.notifyDataSetChanged()
        }
        vm.areaSuccess.observe(this){
            carAdapter.data.clear()
            carAdapter.data.addAll(it)
            carAdapter.notifyDataSetChanged()
        }
    }

}